﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.IO;
using System.Reflection;
using Bzure.Common.Caching;
using Bzure.Mvc.ResourceAccess;
using Bzure.Common.Core;
using System.ComponentModel.Composition;

namespace Bzure.Apps.Security.ResourceFiles
{
    [Export(typeof(IContractFactory<IResourceAccess>)), ExportMetadata("ProviderName", ResouceAccessBuilder.PolicyModelKey)]
    public class ResouceAccessBuilder : IContractFactory<IResourceAccess>
    {
        const string PolicyModelKey = "SecurityApp";
        /// <summary>
        /// 契约实现的版本号
        /// </summary>
        public float ContractVersion { get { return 1.0F; } }
        public IResourceAccess Build()
        {
            return new ResourceAccess();
        }
    }
    public class ResourceAccess : IResourceAccess
    {
        public string GetCSS(string CssName)
        {
            StreamReader reader = null;
            Assembly assembly = typeof(Styles.Style).Assembly;
            reader = new StreamReader(assembly.GetManifestResourceStream(typeof(Styles.Style), CssName));
            string s = reader.ReadToEnd();
            return s;
        }
        public Stream GetImage(string ImageName)
        {
            Assembly assembly = typeof(Images.Image).Assembly;
            return assembly.GetManifestResourceStream(typeof(Images.Image), ImageName);
        }
        public string GetScript(string ScriptName)
        {
            StreamReader reader = null;
            Assembly assembly = typeof(Scripts.Script).Assembly;
            reader = new StreamReader(assembly.GetManifestResourceStream(typeof(Scripts.Script), ScriptName));
            string s = reader.ReadToEnd();
            return s;
        }
    }

}
